// pages/balance-log/index.js
const { getBalanceLog } = require('../../api/member');
const { hidePullDownLoading } = require('../../common/platform');
const { PageBase } = require('../../mixins/page');

Page({
    mixins: [PageBase],
    data: {
        balanceLogList: [],
        pageSize: 10,
        balancePageNumber: 1,
    },
    onLoad: async function (options) {
        await this.handleBalanceLog();
    },
    async onPullDownRefresh () {
        await this.handleBalanceLog();
        hidePullDownLoading();
    },
    async onReachBottom () {
        await this.handleBalanceLogNext();
    },
    async handleBalanceLog() {
        const { pageSize } = this.data;
        const param = {
            page_no: 1,
            page_size: pageSize,
        };
        const list = await getBalanceLog(param);
        this.setData({
            balanceLogList: list,
        });
    },
    async handleBalanceLogNext() {
        const { pageSize, balancePageNumber, balanceLogList } = this.data;
        const pageNumber = balancePageNumber + 1;
        const param = {
            page_no: pageNumber,
            page_size: pageSize,
        };
        const list = await getBalanceLog(param);
        this.setData({
            balanceLogList: [...balanceLogList, ...list],
            balancePageNumber: pageNumber,
        });
    },
})